package com.roy.springboot.security.oauth2.service;



import com.roy.springboot.security.oauth2.entities.User;
import com.roy.springboot.security.oauth2.repositories.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;

/**
 * Created by elloxxn on 12/14/2017.
 */
@Service
public class UserService {
    @Autowired
    private UserRepository repo;

    public PasswordEncoder getPasswordEncoder() {
        return new BCryptPasswordEncoder();
    }

    public void save(User user) {
        user.setPassword(getPasswordEncoder().encode(user.getPassword()));
        repo.save(user);
    }
}
